<%
  # Controllers that use this partial must provide the following variables:
  # comment
  # user

  thread = comment.thread
%>

<% if comment.can_be_voted_on? %>
  <% can_vote = comment.can_be_voted_on_by?(user) %>
  <% vote = comment.get_vote_by(user) %>
  <% comment_voting = thread.config.comment_voting.to_sym %>

  <% if comment_voting == :ld || comment_voting == :l %>
  <% vtype = (comment_voting == :ld) ? 'upvote' : 'like' %>
  <span id="commontator-comment-<%= comment.id %>-<%= vtype %>" class="<%= vtype %>">
    <% if can_vote && (vote.blank? || !vote.vote_flag) %>
      <%= form_tag commontator.upvote_comment_path(comment),
            method: :put,
            remote: true do %>
        <%= image_submit_tag "commontator/upvote.png",
              onmouseover: "this.src='#{image_path("commontator/upvote_hover.png")}'",
              onmouseout: "this.src='#{image_path("commontator/upvote.png")}'" %>
      <% end %>
    <% elsif can_vote %>
      <%= form_tag commontator.unvote_comment_path(comment),
            method: :put,
            remote: true do %>
        <%= image_submit_tag "commontator/upvote_active.png",
              onmouseover: "this.src='#{image_path("commontator/upvote.png")}'",
              onmouseout: "this.src='#{image_path("commontator/upvote_active.png")}'" %>
      <% end %>
    <% else %>
      <div title="You can't vote on your own comment">
        <%= image_tag "commontator/upvote_disabled.png" %>
      </div>
    <% end %>
  </span>
  <% end %>

  <span id="commontator-comment-<%= comment.id %>-vote-count" class="vote-count">
    <% config = thread.config %>
    <%= config.vote_count_proc.call(thread, comment.cached_votes_up, comment.cached_votes_down) %>
  </span>

  <% if comment_voting == :ld %>
  <span id="commontator-comment-<%= comment.id %>-downvote" class="downvote">
    <% if can_vote && (vote.blank? || vote.vote_flag) %>
      <%= form_tag commontator.downvote_comment_path(comment),
            method: :put,
            remote: true do %>
        <%= image_submit_tag "commontator/downvote.png",
              onmouseover: "this.src='#{image_path("commontator/downvote_hover.png")}'",
              onmouseout: "this.src='#{image_path("commontator/downvote.png")}'" %>
      <% end %>
    <% elsif can_vote %>
      <%= form_tag commontator.unvote_comment_path(comment),
            method: :put,
            remote: true do %>
      <%= image_submit_tag "commontator/downvote_active.png",
        onmouseover: "this.src='#{image_path("commontator/downvote.png")}'",
        onmouseout: "this.src='#{image_path("commontator/downvote_active.png")}'" %>
      <% end %>
    <% else %>
    <div title="You can't vote on your own comment">
      <%= image_tag "commontator/downvote_disabled.png" %>
    </div>
    <% end %>
  </span>
  <% end %>
<% end %>
